package com.zwl.swagger;

import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
import com.zwl.swagger.SwaggerProperties.Swagger2Properties;
import com.zwl.swagger.SwaggerProperties.Swagger2Properties.Info;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author zhangweilin
 * @Description: zwlx
 * @date 2020/5/25
 */
@Configuration
@EnableSwagger2
@EnableSwaggerBootstrapUI
@ComponentScan(basePackages = { "com"})
@EnableConfigurationProperties(SwaggerProperties.class)
public class Swagger2Config extends BaseSwagger2Config {

//    @Bean
//	@Qualifier("swaggerAntPathMatcher")
//    public AntPathMatcher swaggerAntPathMatcher() {
//        return new AntPathMatcher();
//    }

    @Autowired
    private SwaggerProperties swaggerProperties;

    @Override
    protected ApiInfo apiInfo(String groupName) {
        Swagger2Properties swagger = swaggerProperties.getCore();
        Info info = swagger.getInfo();

        Info.Contact contact = info.getContact();
        return new ApiInfoBuilder().title(info.getTitle())// 大标题
                .description(info.getDescription())// 详细描述
                .termsOfServiceUrl(info.getTermsOfServiceUrl()).version(info.getVersion())
                .contact(new Contact(contact.getName(), contact.getUrl(), contact.getEmail()))// 作者
                .license(info.getLicense())
                .licenseUrl(info.getLicenseUrl()).build();
    }
}
